package com.redoor.app.stake.basicdata.controller;

import com.github.pagehelper.PageInfo;
import com.redoor.app.stake.basicdata.model.controllerModel.BaseStationCriteria;
import com.redoor.app.stake.basicdata.service.BaseStationService;
import com.redoornetwork.framework.core.response.ResponseResult;
import com.redoornetwork.framework.core.response.ResultGenerator;
import com.yotouch.app.stake.hsf.StationService;
import com.yotouch.app.stake.model.Station;
import com.yotouch.app.stake.model.response.ResponseInt;
import com.yotouch.app.stake.model.response.ResponseStation;
import com.yotouch.app.stake.model.response.ResponseStationList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by wangjunlei on 2018/2/13.
 */

@RestController
@RequestMapping("/api/stations")
@Api(value = "提供HSF站接口API")
public class StationAPIController {

    @Autowired
    private StationService stationService;

    @ApiOperation(value = "分页查询所有站点信息", notes = "分页查询所有站点信息")
    @PostMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit", value = "偏移量", paramType = "query", dataType = "int", required = true, defaultValue = "20"),
            @ApiImplicitParam(name = "offset", value = "起始记录", paramType = "query", dataType = "int", required = true, defaultValue = "0")
    })
    public ResponseResult list(int offset, int limit) {
        ResponseStationList list = stationService.list(offset, limit);
        return ResultGenerator.generatorSuccess(list);
    }

    @ApiOperation(value = "统计国网站(isthird)正常状态站 stationstatus =3 数量", notes = "统计国网站(isthird)正常状态站 stationstatus =3 数量")
    @PostMapping("/sgccTotalCount")
    public ResponseResult sgccTotalCount() {
        ResponseInt count = stationService.sgccTotalCount();
        return ResultGenerator.generatorSuccess(count);
    }


    @ApiOperation(value = "获取国网(isthird)正常状态站 stationstatus =3 列表", notes = "获取国网(isthird)正常状态站 stationstatus =3 列表")
    @PostMapping("/sgccList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit", value = "偏移量", paramType = "query", dataType = "int", required = true, defaultValue = "20"),
            @ApiImplicitParam(name = "offset", value = "起始记录", paramType = "query", dataType = "int", required = true, defaultValue = "1")
    })
    public ResponseResult sgccList(int offset, int limit) {
        ResponseStationList list = stationService.sgccList(offset, limit);
        return ResultGenerator.generatorSuccess(list);
    }

    @ApiOperation(value = "根据站uuid查询站下所有的正常使用的桩数目 stakestatus=3", notes = "根据站uuid查询站下所有的正常使用的桩数目 stakestatus=3")
    @PostMapping("/countStakes")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationUuid", value = "站uuid", paramType = "query", dataType = "String", required = true, defaultValue = "1")
    })
    public ResponseResult countStakes(String stationUuid) {
        ResponseStation station = stationService.countStakes(stationUuid);
        return ResultGenerator.generatorSuccess(station);
    }

    @ApiOperation(value = "统计某状态下的所有公用站数量", notes = "统计某状态下的所有公用站数量 stationstatus 2 待投运,3 运行,8 维护,10 退运,11 停运; Urposetype 1 专用 2 公用")
    @PostMapping("/pueryTotaStatusCount")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationStatus", value = "站状态", paramType = "query", dataType = "int", required = true, defaultValue = "2")
    })
    public ResponseResult pueryTotaStatusCount(int stationStatus) {
        ResponseInt statusCount = stationService.pueryTotaStatusCount(stationStatus);
        return ResultGenerator.generatorSuccess(statusCount);
    }


    @ApiOperation(value = "统计某状态下的所有公用站列表", notes = "统计某状态下的所有公用站列表 stationstatus 2 待投运,3 运行,8 维护,10 退运,11 停运; Urposetype 1 专用 2 公用")
    @PostMapping("/pueryStatusList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationStatus", value = "站状态", paramType = "query", dataType = "int", required = true, defaultValue = "2"),
            @ApiImplicitParam(name = "limit", value = "偏移量", paramType = "query", dataType = "int", required = true, defaultValue = "20"),
            @ApiImplicitParam(name = "offset", value = "起始记录", paramType = "query", dataType = "int", required = true, defaultValue = "1")
    })
    public ResponseResult pueryStatusList(int stationStatus,int offset, int limit) {
        ResponseStationList stationList = stationService.pueryStatusList(offset,limit,stationStatus);
        return ResultGenerator.generatorSuccess(stationList);
    }


    @ApiOperation(value = "统计所有站数", notes = "status=1000")
    @PostMapping("/totalCount")
    public ResponseResult totalCount() {
        ResponseInt count = stationService.totalCount();
        return ResultGenerator.generatorSuccess(count);
    }


    @ApiOperation(value = "根据区域行政编码(districtCode)统计该区域内正常运⾏状态(stationstatus)的国⽹(isthird)充电站数量", notes = "status=1000 stationstatus=3 isthird in (0,1)")
    @PostMapping("/countByDistrict")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "districtcode", value = "区域行政编码", paramType = "query", dataType = "String", required = true, defaultValue = "10000")
    })
    public ResponseResult countByDistrict(String districtcode) {
        ResponseInt count = stationService.countByDistrict(districtcode);
        return ResultGenerator.generatorSuccess(count);
    }


    @ApiOperation(value = "根据区域行政编码(districtCode)统计该区域内正常运⾏状态(stationstatus)的国⽹(isthird)充电站列表", notes = "status=1000 stationstatus=3 isthird in (0,1)")
    @PostMapping("/listByDistrict")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "districtcode", value = "区域行政编码", paramType = "query", dataType = "String", required = true, defaultValue = "10000"),
            @ApiImplicitParam(name = "limit", value = "偏移量", paramType = "query", dataType = "int", required = true, defaultValue = "20"),
            @ApiImplicitParam(name = "offset", value = "起始记录", paramType = "query", dataType = "int", required = true, defaultValue = "1")
    })
    public ResponseResult listByDistrict(String districtcode,int offset, int limit) {
        ResponseStationList list = stationService.listByDistrict(districtcode,offset,limit);
        return ResultGenerator.generatorSuccess(list);
    }

    @ApiOperation(value = "根据省份行政编码(provincecode)统计该区域内充电站数量", notes = "status=1000 provincecode=?")
    @PostMapping("/countByProvince")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "provincecode", value = "省份行政编码", paramType = "query", dataType = "String", required = true, defaultValue = "10000")
    })
    public ResponseResult countByProvince(String provincecode) {
        ResponseInt count = stationService.countByProvince(provincecode);
        return ResultGenerator.generatorSuccess(count);
    }


    @ApiOperation(value = "根据省份行政编码(provincecode)统计该区域内充电站列表", notes = "status=1000 provincecode=?")
    @PostMapping("/listByProvince")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "provincecode", value = "省份行政编码", paramType = "query", dataType = "String", required = true, defaultValue = "10000"),
            @ApiImplicitParam(name = "limit", value = "偏移量", paramType = "query", dataType = "int", required = true, defaultValue = "20"),
            @ApiImplicitParam(name = "offset", value = "起始记录", paramType = "query", dataType = "int", required = true, defaultValue = "1")
    })
    public ResponseResult listByProvince(String provincecode,int offset, int limit) {
        ResponseStationList list = stationService.listByProvince(provincecode,limit,offset);
        return ResultGenerator.generatorSuccess(list);
    }


    @ApiOperation(value = "根据组织机构编码(provinceOrgCode or cityorgcode or partorgcode)获取所有本机构下的站数", notes = "status=1000 provinceOrgCode or cityorgcode or partorgcode=?")
    @PostMapping("/countByOrg")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orgcode", value = "组织机构编码", paramType = "query", dataType = "String", required = true, defaultValue = "10000")
    })
    public ResponseResult countByOrg(String orgcode) {
        ResponseInt count = stationService.countByOrg(orgcode);
        return ResultGenerator.generatorSuccess(count);
    }


    @ApiOperation(value = "根据组织机构编码(provinceOrgCode or cityorgcode or partorgcode)获取所有本机构下的站列表", notes = "status=1000 provinceOrgCode or cityorgcode or partorgcode=?")
    @PostMapping("/listByOrg")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orgcode", value = "省份行政编码", paramType = "query", dataType = "String", required = true, defaultValue = "10000"),
            @ApiImplicitParam(name = "limit", value = "偏移量", paramType = "query", dataType = "int", required = true, defaultValue = "20"),
            @ApiImplicitParam(name = "offset", value = "起始记录", paramType = "query", dataType = "int", required = true, defaultValue = "1")
    })
    public ResponseResult listByOrg(String orgcode,int offset, int limit) {
        ResponseStationList list = stationService.listByOrg(orgcode,limit,offset);
        return ResultGenerator.generatorSuccess(list);
    }


    @ApiOperation(value = "根据组织机构编码(provinceOrgCode or cityorgcode or partorgcode)获取所有本机构下的站以及下一级机构的站列表", notes = "status=1000 provinceOrgCode or cityorgcode or partorgcode=?")
    @PostMapping("/listAllByOrg")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orgcode", value = "省份行政编码", paramType = "query", dataType = "String", required = true, defaultValue = "10000"),
            @ApiImplicitParam(name = "limit", value = "偏移量", paramType = "query", dataType = "int", required = true, defaultValue = "20"),
            @ApiImplicitParam(name = "offset", value = "起始记录", paramType = "query", dataType = "int", required = true, defaultValue = "1")
    })
    public ResponseResult listAllByOrg(String orgcode) {
        ResponseStationList list = stationService.listAllByOrg(orgcode);
        return ResultGenerator.generatorSuccess(list);
    }
}
